package com.qf.controller;

import com.qf.config.RabbitMQConfig;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * projectName:temp_shop
 * author:luo
 * time:2023/3/15 19:09
 */
@RestController
@RequestMapping("/message")
public class SendMessageController {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @GetMapping("/send")
    public String sendMessage() {
        rabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE_TOPIC,"a.b.rabbit.a.b","22本次测试的是Java配置类创建交换机，队列，绑定");
        return "OK";
    }
    @GetMapping("/sendc")
    public String sendMessagec() {
        rabbitTemplate.convertAndSend("exchange_c","c","消费者测试手动应答");
        return "OK";
    }

    /**
     *  防止消息被重复消费
     * @return
     */
    @GetMapping("/sendr")
    public String sendr() {
        String id= UUID.randomUUID().toString();
        CorrelationData correlationData = new CorrelationData();
        correlationData.setId(id);

        rabbitTemplate.convertAndSend("exchange_c","c","防止消息被重复消费",correlationData);
        return "OK";
    }
}
